package com.wyh.service.serviceImpl.gfiveImpl.tree_service_impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyh.domain.vo.gfive.treeVo.ProjectVO;
import com.wyh.mapper.gfivemapper.tree_mapper.ProjectVOMapper;
import com.wyh.service.gfive.tree_service.IProjectVOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ProjectVOServiceImpl extends ServiceImpl<ProjectVOMapper,ProjectVO> implements IProjectVOService {

    @Autowired
    private ProjectVOMapper mapper;
    @Override
    public List<ProjectVO> findAll() {
        return mapper.selectAll();
    }

    @Override
    public List<ProjectVO> findListY(int id) {
        QueryWrapper<ProjectVO> wrapper = new QueryWrapper<>();
        wrapper.eq("superiorid",id).eq("isconnected","Y");
        List<ProjectVO> projectVOList = mapper.selectList(wrapper);
        return projectVOList;
    }

    @Override
    public List<ProjectVO> findListN(int id) {
        QueryWrapper<ProjectVO> wrapper = new QueryWrapper<>();
        wrapper.eq("superiorid",id).eq("isconnected","N");
        List<ProjectVO> projectVOList = mapper.selectList(wrapper);
        return projectVOList;
    }

    @Override
    public List<ProjectVO> findAllByConnected(String account) {
        List<ProjectVO> projectVOList = mapper.selectByIdWithManageProject(account);
        QueryWrapper<ProjectVO> wrapper = new QueryWrapper<>();
        wrapper.eq("type",0).ne("state",-1);
        List<ProjectVO> projectVOList1 = mapper.selectList(wrapper);
        projectVOList.addAll(projectVOList1);

        return projectVOList;
    }

    @Override
    public List<Integer> findHousesIds() {
        QueryWrapper<ProjectVO> wrapper = new QueryWrapper<>();
        wrapper.eq("type",1).ne("state",-1).ne("state",0);
        List<ProjectVO> projectVOList = mapper.selectList(wrapper);
        return projectVOList.stream().map(projectVO -> {
            return projectVO.getId();
        }).collect(Collectors.toList());
    }
}
